package utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.output.Format;

public class Dom{
	
	public static Document getXMLFile(String url){
		SAXBuilder sxb = new SAXBuilder();
		Document document = null;
		
		try{
			document = sxb.build(new File("XMLFiles/"+url));	
		}catch(Exception exc){
			System.out.println("Invalid file");
		}
		
		return document;
	}
	
	public static void saveFile(Document dom, String file){
	     XMLOutputter exit = new XMLOutputter(Format.getPrettyFormat());
	     try{
	    	 FileOutputStream stream = new FileOutputStream(new File("XMLFiles/"+file));
	    	 exit.output(dom, stream);
	    	 stream.close();
	    	 
	     }catch(FileNotFoundException exc){
	    	 System.out.println("File can't be found");
	    	 
	     }catch(IOException exc){
	    	 System.out.println("Error");
	    	 
	     }
	}
}
